package logic

import (
	"context"
	"srv/sesame"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDetailGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailGoodsLogic {
	return &DetailGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DetailGoodsLogic) DetailGoods(req *types.DetailGoodsRequest) (resp *types.Response, err error) {
	_, err = l.svcCtx.SesameSrv.DetailGoods(l.ctx, &sesame.DetailGoodsRequest{
		GoodsId: int64(req.GoodsId),
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "获取商品详情失败",
		}, err
	}
	if req.GoodsId == 0 {
		return &types.Response{
			Code: 500,
			Msg:  "商品不存在",
		}, err
	}

	return &types.Response{
		Code: 200,
		Msg:  "获取商品详情成功",
	}, nil

}
